package com.ss.android.article.base.ui;

import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.download.DownloadAdapterProxy;
import com.ss.android.common.download.DownloadShortInfo;
import com.ss.android.common.util.ToolUtils;

import org.json.JSONObject;

final class b implements Runnable {
    private final com.ss.android.article.base.ui.AdButtonLayout.a e;
    private final DownloadShortInfo a;
    private final int b;
    private final long c;
    private final long d;

    b(com.ss.android.article.base.ui.AdButtonLayout.a arg1, DownloadShortInfo arg2, int arg3, long arg4, long arg6) {
        this.e = arg1;
        this.a = arg2;
        this.b = arg3;
        this.c = arg4;
        this.d = arg6;

    }

    public final void run() {
        com.ss.android.article.base.feature.b.a v1;
        long v12 = 0;
        int v5 = 2;
        if (this.a != null && this.a.id == this.e.a) {
            Logger.d("AdButtonLayout", "mId = " + this.e.a + " info.id = " + this.a.id + " fileName = " + this.a.fileName);
            try {
                String v2 = "feed_download_ad";
                this.e.b.h = 2;
                if (!this.e.b.a()) {
                    v2 = "detail_download_ad";
                    this.e.b.h = 1;
                }

                this.e.b.f = this.a;
                String v0_1 = "";
                this.e.b.a(true);
                if (this.b == 1) {
                    Logger.d("AdButtonLayout", "mAppAd.mId = " + this.e.b.e.id + ", status == DownloadNotifier.TYPE_ACTIVE");
                    v0_1 = this.e.b.getResources().getString(com.ss.android.article.browser.R.string.kf);
                } else if (this.b == v5) {
                    Logger.d("AdButtonLayout", "mAppAd.mId = " + this.e.b.e.id + ", status == DownloadNotifier.TYPE_WAITING");
                    v0_1 = this.e.b.getResources().getString(com.ss.android.article.browser.R.string.ki);
                    v1 = android.support.design.a.c(this.e.b.e.id);
                    if (v1 != null) {
                        v1.c += System.currentTimeMillis() - v1.b;
                        v1.b = System.currentTimeMillis();
                        android.support.design.a.a(v1, false);
                    }
                } else if (this.b == 3) {
                    Logger.d("AdButtonLayout", "mAppAd.mId = " + this.e.b.e.id + ", status == DownloadNotifier.TYPE_COMPLETE");
                    if (this.e.b.f.b == 16) {
                        com.ss.android.article.base.feature.b.a v0_2 = android.support.design.a.c(this.e.b.e.id);
                        Logger.d("AdButtonLayout", "mAppAd.mId = " + this.e.b.e.id + ", download fail");
                        if (v0_2 != null) {
                            long v6 = v0_2.c + (System.currentTimeMillis() - v0_2.b);
                            String v1_1 = DownloadAdapterProxy.inst().getFailedReson(this.e.b.a, this.e.b.f.id);
                            JSONObject v8 = new JSONObject();
                            v8.put("fail_status", v1_1);
                            v8.put("log_extra", this.e.b.e.logExtra);
                            Logger.d("AdButtonLayout", "mAppAd.mId = " + this.e.b.e.id + ", download failed, duration = " + v6 + ", failedReason = " + v1_1);
                            MobAdClickCombiner.onAdEvent(this.e.b.a, v2, "download_failed", this.e.b.e.id, v6, v8, 2);
                            android.support.design.a.a(v0_2, true);
                        }

                        v0_1 = this.e.b.getResources().getString(com.ss.android.article.browser.R.string.kh);
                        this.e.b.a(false);
                    } else {
                        if (this.e.b.f.b == 8) {
                            if (!ToolUtils.d(this.e.b.a, this.e.b.f.fileName)) {
                                v0_1 = this.e.b.getResources().getString(com.ss.android.article.browser.R.string.k9);
                            } else if (!android.support.design.a.isTextEmpty(this.e.b.e.btnTxt)) {
                                v0_1 = this.e.b.e.btnTxt;
                            } else {
                                v0_1 = this.e.b.getResources().getString(com.ss.android.article.browser.R.string.ke);
                            }

                            v1 = android.support.design.a.c(this.e.b.e.id);
                            if (v1 == null) {
//                                goto label_73;
                            } else {
                                Logger.d("AdButtonLayout", "mAppAd.mId = " + this.e.b.e.id + ", download success, duration = " + (System.currentTimeMillis() - v1.b + v1.c));
                                android.support.design.a.a(v1, true);
//                            goto label_73;
                            }
                        } else if (this.e.b.f.b != 32) {
//                            goto label_73;
                        } else {

                            v0_1 = this.e.b.getResources().getString(com.ss.android.article.browser.R.string.ke);
                            MobAdClickCombiner.onAdEvent(this.e.b.a, v2, "install_finish", this.e.b.e.id, 0, this.e.b.e.logExtra, this.e.b.h);
                        }
                    }
                }

                label_73:
                UIUtils.setText(this.e.b.d, ((CharSequence) v0_1));
                if (this.c > v12) {
                    this.e.b.c.setProgress(((int) (this.d * 100 / this.c)));
                    return;
                }

                this.e.b.c.setProgress(0);
            } catch (Exception v0) {
                v0.printStackTrace();
            }
        }
    }
}

